<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="http://localhost:8080/socket.io/socket.io.js"></script>
    <script>
        let sock = io.connect('ws://localhost:8080/');
        window.onload = function () {
            let username = document.getElementById('username');
            let password = document.getElementById('password');
            let logup = document.getElementById('logup');
            let login = document.getElementById('login');

            logup.addEventListener('click', function () {
                sock.emit('logup', username.value, password.value);
            })
            sock.on('logup-ren', (code, msg) => {
                if (code) {
                    alert(msg);
                } else {
                    alert(msg);
                }
            })
            sock.on('login-ren', (code, msg) => {
                if (code) {
                    alert(msg);
                } else {
                    alert(msg);
                }
            })
            login.addEventListener('click', function () {
                sock.emit('login', username.value, password.value);
            })

        }
    </script>
</head>

<body>
    <form action="">
        username:
        <input type="text" name="user" id="username">
        <br> password:
        <input type="password" name="user" id="password">
        <br>
        <input id="logup" type="button" value="注册">
        <input id="login" type="button" value="提交">

    </form>
</body>

</html>